//手机号校验规则（弱校验）
function validateMobile(mobile){
  var reg = /^1[34578]\d{9}$/;
  var result = true;
  if(!reg.test(mobile)){//手机号不符合规则
    wx.showModal({
      title: '请输入正确的手机号码!',
      showCancel:false
    })
    result = false;
  }
  return result;
}

//校验密码，6-10位字母、数字、下划线
function validatePass(pass){
  var result = true;
  var patrn = /^(\w){6,10}$/;
  if (!patrn.exec(s)){
    wx.showModal({
      title: '密码为6-10位',
      showCancel:false
    })
    result = false;
  }
    
  return result;
}

//校验不得为空
function validateEmpty(val,remind){
  var result = true;
  if (typeof(val) == 'undefined'||val.length<1){
    wx.showModal({
      title: remind,
      showCancel:false
    })
    result = false;
  }
  var emoji = /\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDE4F]/g;
  if (emoji.test(val)){
    wx.showModal({
      title: '请勿使用emoji表情!',
      showCancel:false
    })
    result = false;
  }
  return result;
}


//校验为数字(可为空)  length为0 则不校验长度
function validateNumber(val, length, remind) {
  if (typeof (val) == 'undefined' || val.length < 1) return true;
  var result = true;
  if (!/^\d+$/.test(val)) {
    wx.showModal({
      title: remind,
      showCancel:false
    })
    result = false;
  } else if (length > 0 && val.length < length) {
    wx.showModal({
      title: remind,
      showCancel:false
    })
    result = false;
  }
  return result;
}

//校验不为空且为数字  length为0 则不校验长度
function validateInteger(val,length,remind){
  var result = true;
  if (typeof(val)=='undefined'||val.length<1||!/^\d+$/.test(val)) {
    wx.showModal({
      title: remind,
      showCancel:false
    })
    result = false;
  } else if (length > 0 && val.length != length) {
    wx.showModal({
      title: remind,
      showCancel:false
    })
    result = false;
  }
  return result;
}

module.exports = {
  validateMobile: validateMobile,
  validatePass: validatePass,
  validateEmpty:validateEmpty,
  validateInteger: validateInteger,
  validateNumber: validateNumber
}
